package org.nfyszny.zzzs.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.nfyszny.zzzs.modules.entity.ZzzsFertilizationManagement;
import org.nfyszny.zzzs.modules.mapper.ZzzsFertilizationManagementMapper;
import org.nfyszny.zzzs.modules.service.IZzzsFertilizationManagementService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 施肥管理
 * @Author: jeecg-boot
 * @Date: 2022-11-10
 * @Version: V1.0
 */
@Service
public class ZzzsFertilizationManagementServiceImpl extends ServiceImpl<ZzzsFertilizationManagementMapper, ZzzsFertilizationManagement> implements IZzzsFertilizationManagementService {

    @Override
    public void switchStatus(String id, Integer status) {

        ZzzsFertilizationManagement management = new ZzzsFertilizationManagement();
        management.setId(id);
        management.setStatus(status);
        System.out.println("management = " + management);
        baseMapper.updateById(management);
    }

    @Override
    public IPage<ZzzsFertilizationManagement> pageList(Page<ZzzsFertilizationManagement> page, QueryWrapper<ZzzsFertilizationManagement> queryWrapper) {
        Page<ZzzsFertilizationManagement> managementPage = this.page(page, queryWrapper);

        List<ZzzsFertilizationManagement> records = managementPage.getRecords();
        //根据state变成boolean类型值方便页面渲染
        managementPage.setRecords(records.stream().map(item -> {
            item.setStatusBoolean(item.getStatus() == 1);
            return item;
        }).collect(Collectors.toList()));
        return managementPage;
    }
}
